<template>
  <div class="app-container">
    <el-form :show-message="!($route.query.isInfo || isInfo)" ref="elForm" :disabled="$route.query.isInfo || isInfo"
      :model="formData" :rules="rules" size="medium" label-width="120px">
      <h2 style="text-align: center">监督记录</h2>
      <h4 class="form-header h4">基础信息</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="质量监督计划" prop="planId">
            <el-select v-model="formData.planId" placeholder="请选择质量监督计划" clearable @change="changePlan"
              :style="{ width: '100%' }">
              <el-option v-for="(item, index) in planList" :key="index" :label="item.year + '年度质量监督计划'"
                :value="item.yearQualityMonitorPlanId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检测项目" prop="jcxm" v-if="!($route.query.isInfo || isInfo)">
            <el-select v-model="formData.jcxmId" placeholder="请选择检测项目" clearable @change="changeItem"
              :style="{ width: '100%' }">
              <el-option v-for="(item, index) in itemList" :key="index" :label="item.monitorProject"
                :value="item.yearQualityMonitorPlanItemId"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="检测项目" prop="wtsQt" v-else>
            <el-input v-model="formData.jcxm" placeholder="检测项目"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="8">
          <el-form-item label="主持人">
            {{ formData.host }}
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="监督对象" prop="jddxId">
            <UserDialog v-if="other" :disabled="$route.query.isInfo || isInfo" v-model="formData.jddxId"
              @change="changeUser">
            </UserDialog>
            <el-select v-else v-model="formData.jddxId" placeholder="请选择监督对象" clearable :style="{ width: '100%' }">
              <el-option v-for="(item, index) in userList" :key="index" :label="item.nickName"
                :value="item.userId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="监督日期" prop="jdrq">
            <el-date-picker v-model="formData.jdrq" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
              :style="{ width: '100%' }" placeholder="请选择监督日期" clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="监督重点" prop="jdzd">
            <el-checkbox-group v-model="formData.jdzd" style="display:flex;align-items:start">
              <el-checkbox label="新上岗人员"></el-checkbox>
              <el-checkbox label="转岗人员"></el-checkbox>
              <div style="margin-left:30px">
                <el-input v-model="formData.jdzdQt" placeholder="其他"></el-input>
              </div>
            </el-checkbox-group>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">

        <el-col :span="12">
          <el-form-item label="监督形式" prop="jdxs">
            <el-checkbox-group v-model="formData.jdxs">
              <el-checkbox label="提问"></el-checkbox>
              <el-checkbox label="实际操作"></el-checkbox>
              <el-checkbox label="检查技术资料(详见附件)"></el-checkbox>
              <!-- <el-checkbox label="禁用" disabled></el-checkbox>
              <el-checkbox label="选中且禁用" disabled></el-checkbox> -->
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4">委托书(现场检测、业务大厅)</h4>
      <el-row :gutter="15">
        <el-col :span="10">
          <el-form-item label="委托书信息是否齐全" label-width="200px" prop="wtsSfqq">
            <el-radio-group :disabled="formData.wtsBsy" v-model="formData.wtsSfqq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="检测依据是否明确" label-width="200px" prop="wtsSfmq">
            <el-radio-group :disabled="formData.wtsBsy" v-model="formData.wtsSfmq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="不适用" prop="wtsBsy">
            <!-- <el-radio v-model="formData.wtsBsy" :label="1">不适用</el-radio> -->
            <el-checkbox label="不适用" v-model="formData.wtsBsy"></el-checkbox>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="其他" prop="wtsQt">
            <el-input v-model="formData.wtsQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4">人员</h4>
      <el-row :gutter="15">
        <el-col :span="10">
          <el-form-item label="是否具备上岗资格" label-width="200px" prop="rySgzg">
            <el-radio-group :disabled="formData.ryBsy" v-model="formData.rySgzg">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="不适用" prop="ryBsy">
            <!-- <el-radio v-model="formData.ryBsy" :label="1">不适用</el-radio> -->
            <el-checkbox label="不适用" v-model="formData.ryBsy"></el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="其他" prop="ryQt">
            <el-input v-model="formData.ryQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <h4 class="form-header h4">设备</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="是否满足规范要求" label-width="150px" prop="sbGfyq">
            <el-radio-group :disabled="formData.sbBsy" v-model="formData.sbGfyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="是否在有效的检定/校准周期内，且检定/校准满足要求" label-width="400px" prop="sbJdyq">
            <el-radio-group :disabled="formData.sbBsy" v-model="formData.sbJdyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="不适用" prop="sbBsy">
            <el-checkbox label="不适用" v-model="formData.sbBsy"></el-checkbox>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="其他" prop="sbQt">
            <el-input v-model="formData.sbQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>

      </el-row>

      <h4 class="form-header h4">样品</h4>
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="流转过程中是否具备唯一标识" label-width="250px" prop="ypWybs">
            <el-radio-group :disabled="formData.ypBsy" v-model="formData.ypWybs">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否及时标注样品检测状态" label-width="200px" prop="ypJczt">
            <el-radio-group :disabled="formData.ypBsy" v-model="formData.ypJczt">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="样品制备、状态调节是否满足规范要求" label-width="260px" prop="ypGfyq">
            <el-radio-group :disabled="formData.ypBsy" v-model="formData.ypGfyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="其他" prop="ypQt">
            <el-input v-model="formData.ypQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不适用" prop="ypBsy">
            <el-checkbox label="不适用" v-model="formData.ypBsy"></el-checkbox>

          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4">检测依据</h4>
      <el-row :gutter="15">
        <el-col :span="10">
          <el-form-item label="检测依据是否现行有效，特殊情况是否取得客户同意" label-width="350px" prop="jcyjKhty">
            <el-radio-group :disabled="formData.jcyjBsy" v-model="formData.jcyjKhty">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="不适用" prop="jcyjBsy">
            <el-checkbox label="不适用" v-model="formData.jcyjBsy"></el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="其他" prop="jcyjQt">
            <el-input v-model="formData.jcyjQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4">检测环境</h4>
      <el-row :gutter="15">
        <el-col :span="10">
          <el-form-item label="检测环境(温度、湿度等)是否满足规范要求" label-width="350px" prop="jchjGfyq">
            <el-radio-group :disabled="formData.jchjBsy" v-model="formData.jchjGfyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="不适用" prop="jchjBsy">
            <el-checkbox label="不适用" v-model="formData.jchjBsy"></el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="其他" prop="jchjQt">
            <el-input v-model="formData.jchjQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <h4 class="form-header h4">检测过程</h4>
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="是否按照所选用的检测依据进行试验" label-width="250px" prop="jcghJxsy">
            <el-radio-group :disabled="formData.jcgcBsy" v-model="formData.jcghJxsy">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="设备操作、检测过程是否熟练" label-width="210px" prop="jcgcCzsl">
            <el-radio-group :disabled="formData.jcgcBsy" v-model="formData.jcgcCzsl">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="设备台账是否记录及时" label-width="260px" prop="jcgcJsjl">
            <el-radio-group :disabled="formData.jcgcBsy" v-model="formData.jcgcJsjl">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="现场安全措施是否布置到位" label-width="260px" prop="jcgcAqdw">
            <el-radio-group :disabled="formData.jcgcBsy" v-model="formData.jcgcAqdw">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="其他" prop="jcgcQt">
            <el-input v-model="formData.jcgcQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不适用" prop="jcgcBsy">
            <el-checkbox label="不适用" v-model="formData.jcgcBsy"></el-checkbox>

          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4">原始记录</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="是否为受控版本" label-width="200px" prop="ysjlSkbb">
            <el-radio-group :disabled="formData.ysjlBsy" v-model="formData.ysjlSkbb">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="填写是否规范、完整" label-width="210px" prop="ysjlSfgf">
            <el-radio-group :disabled="formData.ysjlBsy" v-model="formData.ysjlSfgf">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="数据是否准确" label-width="200px" prop="ysjlSfzq">
            <el-radio-group :disabled="formData.ysjlBsy" v-model="formData.ysjlSfzq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="其他" prop="ysjlQt">
            <el-input v-model="formData.ysjlQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不适用" prop="ysjlBsy">
            <el-checkbox label="不适用" v-model="formData.ysjlBsy"></el-checkbox>

          </el-form-item>
        </el-col>
      </el-row>

      <h4 class="form-header h4">检测报告</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="检测报告信息内容是否存在不一致性" label-width="300px" prop="jcbgByzx">
            <el-radio-group :disabled="formData.jcbgBsy" v-model="formData.jcbgByzx">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检测报告的信息内容是否满足规范及质量体系要求" label-width="380px" prop="jcbgTxyq">
            <el-radio-group :disabled="formData.jcbgBsy" v-model="formData.jcbgTxyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="检测报告的数据处理是否准确" label-width="250px" prop="jcbgSjsfzq">
            <el-radio-group :disabled="formData.jcbgBsy" v-model="formData.jcbgSjsfzq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="检测报告的结论是否准确" label-width="150px" prop="jcbgJlsfzq">
            <el-radio-group :disabled="formData.jcbgBsy" v-model="formData.jcbgJlsfzq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="检测报告的审核、批准流程是否正确，且人员是否满足行业及质量体系要求" label-width="530px" prop="jcbgYq">
            <el-radio-group :disabled="formData.jcbgBsy" v-model="formData.jcbgYq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <!-- <el-col :span="8">
          <el-form-item label="要求" prop="jcbgYq">
            <el-radio-group v-model="formData.jcbgYq">
              <el-radio :label="0">是</el-radio>
              <el-radio :label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="其他" prop="jcbgQt">
            <el-input v-model="formData.jcbgQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不适用" prop="jcbgBsy">
            <el-checkbox label="不适用" v-model="formData.jcbgBsy"></el-checkbox>
          </el-form-item>
        </el-col>
      </el-row>

      <h4 class="form-header h4">工作程序(业务大厅)</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="样品收样数量及状态是否满足规范检测要求" label-width="250px" prop="gzcxGfyq">
            <el-radio-group :disabled="formData.gzcxBsy" v-model="formData.gzcxGfyq">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="发样过程是否能够保持样品的唯一性标识" label-width="210px" prop="gzcxWybs">
            <el-radio-group :disabled="formData.gzcxBsy" v-model="formData.gzcxWybs">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="留样过程符合规范及质量体系要求、入库出库登记及时、准确" label-width="350px" prop="gzcxRkdj">
            <el-radio-group :disabled="formData.gzcxBsy" v-model="formData.gzcxRkdj">
              <el-radio label="0">是</el-radio>
              <el-radio label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="其他" prop="gzcxQt">
            <el-input v-model="formData.gzcxQt" placeholder="其他"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不适用" prop="gzcxBsy">
            <el-checkbox label="不适用" v-model="formData.gzcxBsy"></el-checkbox>
          </el-form-item>
        </el-col>
      </el-row>
      <h4 class="form-header h4" style="margin-top: 20px">附件信息</h4>
      <el-form-item label="" prop="attachmentUrl">
        <FileUpload :isDelete="!$route.query.isInfo" v-model="formData.attachmentUrl"></FileUpload>
      </el-form-item>
      <!-- <h4 class="form-header h4">监督结论</h4>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="该监督对象是否存在不符合工作情况" label-width="250px" prop="innerManagerAuditId">
            <el-radio-group v-model="formData.authorization" style="display:flex;align-items:start">
              <el-radio :label="0">存在</el-radio>
              <el-radio :label="1">不存在</el-radio>
              <div style="margin-left:30px">
                <el-input v-if="formData.authorization == 0" v-model="formData.status" placeholder="描述"></el-input>
              </div>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否具备工作能力" label-width="210px" prop="innerManagerAuditId">
            <el-radio-group v-model="formData.authorization">
              <el-radio :label="0">是</el-radio>
              <el-radio :label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="日期" prop="publishDate">
            <el-date-picker v-model="formData.publishDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
              :style="{ width: '100%' }" placeholder="请选择日期" clearable></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    
      
      <h4 class="form-header h4">监督对象确认</h4>
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="对监督结果是否又异议" label-width="210px" prop="innerManagerAuditId">
            <el-radio-group v-model="formData.authorization">
              <el-radio :label="0">是</el-radio>
              <el-radio :label="1">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="日期" prop="publishDate">
            <el-date-picker v-model="formData.publishDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
              :style="{ width: '100%' }" placeholder="请选择日期" clearable></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <h4 class="form-header h4">后续处理</h4>
      <el-row :gutter="15">
        <el-col :span="12">
          <el-form-item label="是否可以上岗" label-width="210px" prop="innerManagerAuditId">
            <el-radio-group v-model="formData.authorization">
              <el-radio :label="0">可以上岗</el-radio>
              <el-radio :label="1">不可上岗(需培训后重新监督)</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="日期" prop="publishDate">
            <el-date-picker v-model="formData.publishDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
              :style="{ width: '100%' }" placeholder="请选择日期" clearable></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row> -->

      <el-col :span="24" v-if="btnShow">
        <el-form-item label-width="0" style="text-align: center; margin-top: 30px">
          <el-button v-if="!($route.query.isInfo || isInfo)" type="primary" @click="submitForm(1)">提交</el-button>
          <el-button v-if="!($route.query.isInfo || isInfo)" type="primary" @click="submitForm(0)">暂存</el-button>
          <el-button :disabled="false" @click="resetForm">返回</el-button>
        </el-form-item>
      </el-col>
    </el-form>
  </div>
</template>

<script>
import store from "@/store";

import {
  selectList as selectListplan,
  managerAuditInfo,
} from "@/api/quality/manageAudit/plan.js";
import {
  supervisionRecordAdd,
  updategSupervisionRecord,
  supervisionRecordInfo,
  planList,
  itemList,
  userList,
} from "@/api/quality/supervision/record.js";
export default {
  components: {},

  dicts: ["sys_manager_item"],

  props: {
    isInfo: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
      default: "",
    },
    btnShow: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      planInfo: {},
      formData: {
        jdzd: [],
        jdzdQt: '',
        jdxs: [],
        wtsSfqq: null,
        wtsSfmq: null,
        wtsQt: "",
        wtsBsy: null,
        rySgzg: null,
        ryQt: '',
        ryBsy: null,
        sbGfyq: null,
        sbJdyq: null,
        sbQt: '',
        sbBsy: null,
        ypWybs: null,
        ypJczt: null,
        ypGfyq: null,
        ypQt: '',
        ypBsy: null,
        jcyjKhty: null,
        jcyjQt: '',
        jcyjBsy: null,
        jchjGfyq: null,
        jcghJxsy: null,
        jcgcCzsl: null,
        jcgcJsjl: null,
        jcgcAqdw: null,
        ysjlSkbb: null,
        ysjlSfgf: null,
        ysjlSfzq: null,
        ysjlQt: '',
        ysjlBsy: null,
        jcbgByzx: null,
        jcbgTxyq: null,
        jcbgSjsfzq: null,
        jcbgJlsfzq: null,
        jcbgPzsfzq: null,
        jcbgYq: null,
        jcbgBsy: null,
        jcbgQt: '',
        gzcxGfyq: null,
        gzcxQt: "",
        gzcxWybs: null,
        gzcxRkdj: null,
        gzcxBsy: null,
      },
      rules: {
        logUserId: [
          {
            required: true,
            message: "请选择记录人",
            trigger: "change",
          },
        ],
        auditDate: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],
        innerManagerAuditId: [
          {
            required: true,
            message: "请选择管理评审计划",
            trigger: "change",
          },
        ],
        item: [
          {
            required: true,
            message: "请选择评审项目",
            trigger: "change",
          },
        ],

        deptId: [
          {
            required: true,
            message: "请选择部门",
            trigger: "change",
          },
        ],

        result: [
          {
            required: true,
            message: "请输入单项结论",
            trigger: "blur",
          },
        ],
        adapt: [
          {
            required: true,
            message: "请输入文件适应性",
            trigger: "blur",
          },
        ],
        run: [
          {
            required: true,
            message: "请输入运行情况",
            trigger: "blur",
          },
        ],
      },
      deptOptions: [],
      planList: [],
      itemList: [],
      userList: [],
      other: false
    };
  },
  computed: {},
  watch: {},
  created() {
    if (this.$route.query.isEdit || this.$route.query.isInfo || this.isInfo) {
      this.getinfo();
    }
    if (this.$route.query.planId) {
      this.formData.innerManagerAuditId = Number(this.$route.query.planId);
      this.changePlan(Number(this.$route.query.planId));
    }
    this.getPlan();
  },
  mounted() {
    this.formData.jdyName = this.$store.state.user.nickName
    this.formData.jdyId = this.$store.state.user.id;
  },
  methods: {
    dictType(e, i) {
      // console.log(e);
      // console.log(this.dict.type.sys_manager_item);
      let arr = this.dict.type.sys_manager_item
      arr.forEach((item, index) => {
        //当前选的与数组中的相同 不让其显示，且num不存在时
        if (item.value == e) {
          console.log('.././././.');
          // this.$set(this.dict.type.sys_manager_item,index,)
          item.disabled = true
          item.num = i
          this.$forceUpdate()
          // this.dict.type.sys_manager_item.splice(index,1)
        } else if (item.num == i) {
          console.log(item.num, '展开了已选的下拉框');
          item.disabled = false
          item.num = null
          this.$forceUpdate()
        }

      });
      console.log(this.dict.type.sys_manager_item);
    },
    changePic(e, i) {
      console.log(this.dict.type.sys_manager_item);
    },
    changeUser(e) {
      this.formData.jddxName = e.nickName;
    },
    changePlan(e) {
      console.log(e);
      if (e) {
        itemList({ planId: e }).then((response) => {
          const obj = {
            yearQualityMonitorPlanItemId: 0,
            monitorProject: '其他',
          }
          this.itemList = response.data
          this.itemList.push(obj)
        });
      }
    },
    changeItem(i) {
      // let row= this.itemList.find((e) => e.monitorProject == e);
      // let row = this.itemList.find((e) => e.yearQualityMonitorPlanItemId == i);
      this.formData.itemId = i
      if (i && i != 0) {
        this.other = false
        userList({ yearQualityMonitorPlanItemId: i }).then((response) => {
          this.userList = response.data
        });
      } else {
        this.other = true
      }
    },
    handleAdd() {
      this.formData.infoList.push({
        item: "",
        result: "",
        adapt: "",
        run: "",
      });
    },
    handleDele(e) {
      if (this.formData.infoList.length == 1) return;
      this.formData.infoList.splice(e, 1);
    },

    getPlan() {
      planList().then((response) => {
        this.planList = response.data;
      });
    },

    getinfo() {
      supervisionRecordInfo(this.$route.query.id || this.id).then((response) => {
        this.formData = response.data;
        this.changePlan(this.formData.planId);
        this.changeItem(this.formData.itemId)
        if (this.formData.itemId == 0) {
          this.formData.jcxm = '其他'
          this.formData.planId = '其他'
          this.other = true
        }
        this.formData.jdzd = this.formData.jdzd.split(',')
        this.formData.jdxs = this.formData.jdxs.split(',')
        this.formData.wtsBsy = Boolean(this.formData.wtsBsy)
        this.formData.ryBsy = Boolean(this.formData.ryBsy)
        this.formData.sbBsy = Boolean(this.formData.sbBsy)
        this.formData.ypBsy = Boolean(this.formData.ypBsy)
        this.formData.jcyjBsy = Boolean(this.formData.jcyjBsy)
        this.formData.ysjlBsy = Boolean(this.formData.ysjlBsy)
        this.formData.jcbgBsy = Boolean(this.formData.jcbgBsy)
        this.formData.gzcxBsy = Boolean(this.formData.gzcxBsy)

        console.log(this.formData.wtsBsy);
        // selectList({
        //   innerCheckId: this.$route.query.id || this.id,
        //   createBy: store.state.user.name,
        // }).then((response) => {
        //   this.formData.infoList = response.data;
        // });
      });
      // 获取当前下的 审查明细
    },
    submitForm(e) {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          let query = JSON.parse(JSON.stringify(this.formData));
          if (query.status != 'end') {
            query.status = e == 0 ? 'draft' : 'audit'
          }
          query.jdxs = query.jdxs.toString();
          query.jdzd = query.jdzd.toString();
          if (!this.other) {
            if(this.userList&&this.userList.length>0){
              query.jddxName = this.userList.find((e) => e.userId == query.jddxId).nickName;
            }
            if(this.itemList&&this.itemList.length>0){
              query.jcxm = this.itemList.find((e) => e.yearQualityMonitorPlanItemId == query.jcxmId).monitorProject;
            }
          }
          if (this.formData.qualityMonitorPlanItemId != undefined) {
            updategSupervisionRecord(query).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.resetForm();
            });
          } else {
            supervisionRecordAdd(query).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.resetForm();
            });
          }
        }
      });
    },
    resetForm() {
      this.$tab.closeOpenPage();
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-form-item {
  margin-top: 20px !important;
}
</style>
